package dicts;

import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;

import utils.StringUtil;

public class StateDict implements Serializable {

	private static final long serialVersionUID = 1L;
	
	public static final Map<String, String> US_STATE_MAP = Collections.synchronizedMap(new TreeMap<String, String>());
	static {

		US_STATE_MAP.put("Alabama", "AL");
		US_STATE_MAP.put("Montana", "MT");
		US_STATE_MAP.put("Alaska", "AK ");
		US_STATE_MAP.put("Nebraska", "NE");
		US_STATE_MAP.put("American Samoa", "AS");
		US_STATE_MAP.put("Nevada", "NV");
		US_STATE_MAP.put("Arizona", "AZ");
		US_STATE_MAP.put("New Hampshire", "NH");
		US_STATE_MAP.put("Arkansas", "AR");
		US_STATE_MAP.put("New Jersey", "NJ");
		US_STATE_MAP.put("California", "CA");
		US_STATE_MAP.put("New Mexico", "NM");
		US_STATE_MAP.put("Colorado", "CO");
		US_STATE_MAP.put("New York", "NY");
		US_STATE_MAP.put("Connecticut", "CT");
		US_STATE_MAP.put("North Carolina", "NC");
		US_STATE_MAP.put("Delaware", "DE");
		US_STATE_MAP.put("North Dakota", "ND");
		US_STATE_MAP.put("District of Columbia", "DC");
		US_STATE_MAP.put("Northern Mariana Islands ", "MP");
		US_STATE_MAP.put("Federated States of Micronesia", "FM");
		US_STATE_MAP.put("Ohio", "OH");
		US_STATE_MAP.put("Florida", "FL");
		US_STATE_MAP.put("Oklahoma", "OK");
		US_STATE_MAP.put("Georgia", "GA");
		US_STATE_MAP.put("Oregon", "OR");
		US_STATE_MAP.put("Guam", "GU");
		US_STATE_MAP.put("Palau", "PW");
		US_STATE_MAP.put("Hawaii", "HI");
		US_STATE_MAP.put("Pennsylvania", "PA");
		US_STATE_MAP.put("Idaho", "ID");
		US_STATE_MAP.put("Puerto Rico", "PR");
		US_STATE_MAP.put("Illinois", "IL");
		US_STATE_MAP.put("Rhode Island", "RI");
		US_STATE_MAP.put("Indiana", "IN");
		US_STATE_MAP.put("South Carolina", "SC");
		US_STATE_MAP.put("Iowa", "IA");
		US_STATE_MAP.put("South Dakota", "SD");
		US_STATE_MAP.put("Kansas", "KS");
		US_STATE_MAP.put("Tennessee", "TN");
		US_STATE_MAP.put("Kentucky", "KY");
		US_STATE_MAP.put("Texas", "TX");
		US_STATE_MAP.put("Louisiana", "LA");
		US_STATE_MAP.put("Utah", "UT");
		US_STATE_MAP.put("Maine", "ME");
		US_STATE_MAP.put("Vermont", "VT");
		US_STATE_MAP.put("Marshall Islands", "MH");
		US_STATE_MAP.put("Virgin Islands", "VI");
		US_STATE_MAP.put("Maryland", "MD");
		US_STATE_MAP.put("Virginia", "VA");
		US_STATE_MAP.put("Massachusetts", "MA");
		US_STATE_MAP.put("Washington", "WA");
		US_STATE_MAP.put("Michigan", "MI");
		US_STATE_MAP.put("West Virginia", "WV");
		US_STATE_MAP.put("Minnesota", "MN");
		US_STATE_MAP.put("Wisconsin", "WI");
		US_STATE_MAP.put("Mississippi", "MS");
		US_STATE_MAP.put("Wyoming", "WY");
		US_STATE_MAP.put("Missouri", "MO");
	}

	public static final Map<String, String> CA_STATE_MAP = Collections.synchronizedMap(new TreeMap<String, String>());
	static {
		CA_STATE_MAP.put("Alberta", "AB");
		CA_STATE_MAP.put("British Columbia", "BC");
		CA_STATE_MAP.put("Manitoba", "MB");
		CA_STATE_MAP.put("New Brunswick", "NB");
		CA_STATE_MAP.put("Newfoundland and Labrador", "NL");
		CA_STATE_MAP.put("Northwest Territories", "NT");
		CA_STATE_MAP.put("Nova Scotia", "NS");
		CA_STATE_MAP.put("Nunavut", "NU");
		CA_STATE_MAP.put("Ontario", "ON");
		CA_STATE_MAP.put("Prince Edward Island", "PE");
		CA_STATE_MAP.put("Quebec", "QC");
		CA_STATE_MAP.put("Saskatchewan", "SK");
		CA_STATE_MAP.put("Yukon", "YT");
	}

	public static String US_SHORT(String stateName) {
		String tmpName = "AL";
		if (StringUtil.isEmpty(stateName) || stateName.equals("unknown")) {
			return tmpName;
		} else {
			stateName = stateName.trim().toUpperCase();
		}
		for (Map.Entry<String, String> entry : US_STATE_MAP.entrySet()) {
			String key = entry.getKey();
			String value = entry.getValue();
			if (stateName.equalsIgnoreCase(key)) {
				return value;
			}
			if (stateName.equals(value)) {
				return stateName;
			}
		}

		return tmpName;
	}

	public static String CA_SHORT(String stateName) {
		String tmpName = "AB";
		if (StringUtil.isEmpty(stateName) || stateName.equals("unknown")) {
			return tmpName;
		} else {
			stateName = stateName.trim().toUpperCase();
		}
		for (Map.Entry<String, String> entry : CA_STATE_MAP.entrySet()) {
			String key = entry.getKey();
			String value = entry.getValue();
			if (stateName.equalsIgnoreCase(key)) {
				return value;
			}
			if (stateName.equals(value)) {
				return stateName;
			}
		}
		return tmpName;
	}

	public static void main(String[] args) {
		String s = CA_SHORT("Yukon");
		System.out.println(s);
	}

}
